<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            width: 100px;
            height: 100px;
            background-color: #f00;
            position: absolute;
            left: 1000px;
        }
    </style>
</head>

<body>

    <div class="a"></div>

    <script>

        var oA = document.querySelector('.a');

        // 每隔一段时间向前移动 , 移动到某个位置就停下来
        //   

        // 获取初始值
        var x = oA.offsetLeft;
        var speed = 5;
        var t = setInterval(function () {
            x -= 5;
            oA.style.left = x + 'px' ;
            if(x <= 0) {
                x = 0 ;
                oA.style.left = x + 'px' ;
                clearInterval(t)
            }
        }, 2)



    </script>

</body>

</html>